package coml.jiyun.hp.gjtk_e.model;

import java.util.ArrayList;
import java.util.HashMap;

import coml.jiyun.hp.gjtk_e.bean.ListBean;
import coml.jiyun.hp.gjtk_e.callback.NetCallBack;
import coml.jiyun.hp.gjtk_e.net.ApiService;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class NetMedol {
    public void getData(int i, int id, final NetCallBack netCallBack) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(ApiService.PLAY_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        ApiService service = retrofit.create(ApiService.class);
        HashMap<String, Object> map = new HashMap<>();
        map.put("cid", i);
        Observable<ListBean> observable = service.getdata(id, map);
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ListBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }
                                                
                    @Override
                    public void onNext(ListBean listBean) {
                        ArrayList<ListBean.DataBean.DatasBean> datasBeans = (ArrayList<ListBean.DataBean.DatasBean>) listBean.getData().getDatas();
                        netCallBack.onSecuss(datasBeans);
                    }

                    @Override
                    public void onError(Throwable e) {
                        netCallBack.onFail(e.getMessage());
                    }

                    @Override
                    public void onComplete() {


                    }
                });

    }
}
